//index.js
//获取应用实例
const app = getApp();
var OPEN_ID = wx.getStorageSync('wx_open_id');//储存获取到openid  
var SESSION_KEY = '';//储存获取到session_key  
const user = wx.getStorageSync("user");
const user_token = (wx.getStorageSync('user_token'));
const base_url = app.globalData.base_url;
const util = require('../../utils/util.js');
Page({
  data: {
    isIphoneX: false
  },
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: res => {
        // console.log('手机信息res'+res.model)  
        let modelmes = res.model;
        if (modelmes.search('iPhone X') != -1) {
          this.setData({
            isIphoneX: true
          })
        }
      }
    })
    // console.log(that.data.isIphoneX)
  },
 
  scanningCode: function (event) {
    wx.scanCode({
      onlyFromCamera: true,
      success: (res) => {
        console.log(res)
        var src = res.result;
        src = src.substr(52);
        this.topage(src);
      }
    })
  },
  topage: function (id) {
    // var user_token = (wx.getStorageSync('user_token'))
    // var user_token = '0edbab62c0883f9bf11786208b5c74dc';
    wx.showLoading({
      title: '加载中',
      success: () => {
        wx.request({
          url: base_url + '/Qcode/index',
          method: 'POST',
          data: {
            // 'user_token':user_token,
            'user_token': JSON.parse(wx.getStorageSync("user")).user_token,
            'id': id
          },
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          success: res => {
            console.log(res)
            if (res.data.success == '1') {
              if (res.data.code == '0') {
                wx.navigateTo({
                  url: '../carInfo/index?id=' + id
                })
              } else if (res.data.code == '800') {
                wx.navigateTo({
                  url: '../bindPhone/index?id=' + id
                })
              } else if (res.data.code == '801') {
                wx.navigateTo({
                  url: '../myInfo/index'
                })
              }
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
              if (res.data.code == '110') {
                wx.navigateTo({
                  url: '../logs/logs'
                })
              }
            }
          }
        })
      }
    })
  }
})
